package com.zxy.supplier_system.server.configuration

import com.zxy.supplier_system.server.service.EmployeeOperateRecordService
import com.zxy.supplier_system.server.utils.LoggerDelegate
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.context.properties.bind.ConstructorBinding
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.annotation.EnableScheduling
import org.springframework.scheduling.annotation.Scheduled

@EnableConfigurationProperties(EmployeeOperateRecordProperties::class)
@Configuration
@EnableScheduling
class EmployeeOperateRecordConfiguration(
    private val employeeOperateRecordService: EmployeeOperateRecordService,
){

    companion object{
        private val log by LoggerDelegate()
    }

    @Scheduled(cron = "0 0 4 * * ?", zone = "Asia/Shanghai")
    fun clearExpiredRecordEveryDay(){
        val deletedCount = employeeOperateRecordService.clearExpiredRecord()
        log.info("删除人员操作日志{}条",deletedCount)
    }
}

@ConfigurationProperties(prefix = "employee.operate-record")
class EmployeeOperateRecordProperties @ConstructorBinding constructor(
    val expiredDays:Int,
)